package com.Darkra1Zzz.service.impl;

import com.Darkra1Zzz.dao.SongDao;
import com.Darkra1Zzz.entity.PageInfo;
import com.Darkra1Zzz.entity.Song;
import com.Darkra1Zzz.entity.User;
import com.Darkra1Zzz.service.SongService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author DarkraiZzz
 * @Time 2021/6/30 15:24
 * @Version 1.0
 */
@Service
public class SongServiceImpl implements SongService {
    @Resource
    private SongDao songDao;

    public int updatePlaycountByid(@Param("playcount") int playcount, @Param("songid") int songid){
        return songDao.updatePlaycountByid(playcount,songid);
    }
    public List<Song> querySongs(){
        return songDao.querySongs();
    }

    public PageInfo<Song> querySongsByCondition(Song song, Integer pageIndex, Integer pageSize){
        PageInfo<Song> pageInfo = new PageInfo<Song>();
        pageInfo.setPageIndex(pageIndex);
        pageInfo.setPageSize(pageSize);

        Integer totalCount=songDao.countAllSong(song);

        if (totalCount > 0) {
            pageInfo.setTotalCount(totalCount);
            //每一页显示信息数
            //currentPage = (pageIndex-1)*pageSize  当前页码数减1*最大条数=开始行数
            List<Song> songList= songDao.querySongsByCondition(
                    song.getName(),song.getSinger().getName(),song.getType().getName(),
                    (pageInfo.getPageIndex() - 1) * pageInfo.getPageSize(), pageInfo.getPageSize());
            pageInfo.setList(songList);
        }

        return pageInfo;
    }
}
